package com.shaco.heroproject.activity;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.AuthFailureError;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.ImageRequest;
import com.shaco.heroproject.R;
import com.shaco.heroproject.entity.Result_AllSkill;
import com.shaco.heroproject.volley.VolleySingleton;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by dllo on 15/11/9.
 */
public class SkillInforActivity extends Activity implements View.OnClickListener {
    private Button activity_skill_infor_backBtn;
    private TextView activity_skill_infor_name,activity_skill_infor_level,
            activity_skill_infor_description,activity_skill_infor_direction_of_use;
    private Result_AllSkill ar;
    private VolleySingleton queue;
    private ImageView activity_skill_infor_icon,activity_skill_infor_img;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_skill_infor);
        initView();
        initData();

    }

    private void initData() {
        queue = VolleySingleton.getVolleyIntance();
        getBitmap(ar.getIcon(), activity_skill_infor_icon);
        getBitmap(ar.getImg(), activity_skill_infor_img);

    }

    private void initView() {

        ar = (Result_AllSkill) getIntent().getSerializableExtra(SkillActivity.SER_KEY);
        Log.i("shaco", "ar" + ar.getName());


        activity_skill_infor_name= (TextView) findViewById(R.id.activity_skill_infor_name);
        activity_skill_infor_name.setText(ar.getName()+"");
        activity_skill_infor_level= (TextView) findViewById(R.id.activity_skill_infor_level);
        activity_skill_infor_level.setText(ar.getLevel());
        activity_skill_infor_description= (TextView) findViewById(R.id.activity_skill_infor_description);
        activity_skill_infor_description.setText(ar.getDescription());
        activity_skill_infor_direction_of_use= (TextView) findViewById(R.id.activity_skill_infor_direction_of_use);
        activity_skill_infor_direction_of_use.setText(ar.getDirection_of_use());


        activity_skill_infor_icon= (ImageView) findViewById(R.id.activity_skill_infor_icon);
        activity_skill_infor_img= (ImageView) findViewById(R.id.activity_skill_infor_img);


        activity_skill_infor_backBtn= (Button) findViewById(R.id.activity_skill_infor_backBtn);
        activity_skill_infor_backBtn.setOnClickListener(this);

    }
    /**
     * 通过volley请求图片
     * **/
    public void getBitmap(String url, final ImageView activity_back_story_Iv) {
        ImageLoader.ImageListener listener = ImageLoader.getImageListener(activity_back_story_Iv, R.drawable.ic_launcher, R.drawable.ic_launcher);
        VolleySingleton.getVolleyIntance().getImageLoader().get(url, listener);
        VolleySingleton.getVolleyIntance().getImage(url, new Response.Listener<Bitmap>() {
            @Override
            public void onResponse(Bitmap response) {
                activity_back_story_Iv.setImageBitmap(response);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
////        queue = VolleySingleton.getVolleyIntance();
//        ImageRequest request = new ImageRequest(url,
//                new Response.Listener<Bitmap>() {
//                    @Override
//                    public void onResponse(Bitmap response) {
//                        // 将返回的bitmap图片对象设置到图片组件中
//                        activity_back_story_Iv.setImageBitmap(response);
//                    }
//                }, 0, 0, Bitmap.Config.ARGB_8888, new Response.ErrorListener() {
//            @Override
//            public void onErrorResponse(VolleyError error) {
//                // 打印错误信息
//                error.printStackTrace();
//            }
//        }){
//            @Override
//            public Map<String, String> getHeaders()
//                    throws AuthFailureError {
//                HashMap<String, String> map = new HashMap<String, String>();
//                map.put("Accept-Encoding", "");
//                return map;
//            }
//        };
//        queue.addRequest(request);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.activity_skill_infor_backBtn:
                finish();
                break;
        }
    }
}
